<template>
  <div class="app-container" style="padding: 0 !important;">
    <el-form inline size="small" ref="queryForm" :model="queryParams" v-show="showSearch" label-width="100px">

      <el-form-item>
        <el-radio-group v-model="queryParams.allModel" @change="handleQuery">
          <el-radio-button label="false">预定车型</el-radio-button>
          <el-radio-button label="true">全部车型</el-radio-button>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="车牌号" prop="carNo">
        <el-input style="width:215px;" v-model="queryParams.carNo"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table :data="list">
      <el-table-column label="车辆信息" prop="carNo" width="160" >
        <template slot-scope="scope">
          <div> {{ scope.row.carBrandName + "/" + scope.row.carSeriesName + "/" + scope.row.carModelName }}</div>
          <div><b>{{scope.row.carNo}}</b></div>
        </template>
      </el-table-column>
      <el-table-column label="门店信息" prop="carNo" width="160" >
        <template slot-scope="scope">
          <div>归属:&nbsp;&nbsp;{{scope.row.belongingStoreName}}</div>
          <div>停靠:&nbsp;&nbsp;{{scope.row.locatedStoreName}}</div>
        </template>
      </el-table-column>

      <el-table-column label="保险信息" align="center">
        <el-table-column prop="syDay" label="商业险信息" align="center">
          <template slot-scope="{row}">
            <div v-if="row.syType==1" style="color: #00c585">在保
              <div>剩余&nbsp;{{ row.syDay }}&nbsp;天</div>
            </div>
            <div v-else-if="row.syType==2" style="color: #ff4949">不在保
              <div>超&nbsp;{{ 0 - Number(row.syDay) }}&nbsp;天</div>
            </div>
            <div v-else-if="row.syType==3" style="color: #ffb83b">即将到期
              <div>剩余&nbsp;{{ row.syDay }}&nbsp;天</div>
            </div>
            <div v-else>--</div>
          </template>
        </el-table-column>
        <el-table-column prop="jqDay" label="交强险信息" align="center">
          <template slot-scope="{row}">
            <div v-if="row.jqType==1" style="color: #00c585">在保
              <div>剩余&nbsp;{{ row.jqDay }}&nbsp;天</div>
            </div>
            <div v-else-if="row.jqType==2" style="color: #ff4949">不在保
              <div>超&nbsp;{{ 0 - Number(row.jqDay) }}&nbsp;天</div>
            </div>
            <div v-else-if="row.jqType==3" style="color: #ffb83b">即将到期
              <div>剩余&nbsp;{{ row.jqDay }}&nbsp;天</div>
            </div>
            <div v-else>--</div>
          </template>
        </el-table-column>
      </el-table-column>
      <el-table-column prop="njDay" label="年检信息" align="center">
        <template slot-scope="{row}">
          <div v-if="row.njType==1" style="color: #00c585">已年检
            <div>剩余&nbsp;{{ row.njDay }}&nbsp;天</div>
          </div>
          <div v-else-if="row.njType==2" style="color: #ff4949">已到期
            <div>超&nbsp;{{ 0 - Number(row.njDay) }}&nbsp;天</div>
          </div>
          <div v-else-if="row.njType==3" style="color: #ffb83b">即将到期
            <div>剩余&nbsp;{{ row.njDay }}&nbsp;天</div>
          </div>
          <div v-else>--</div>
        </template>
      </el-table-column>
      <el-table-column prop="useMileage" label="保养信息" align="center">
        <template slot-scope="{row}">
          <div v-if="Number(row.nextMile)>Number(row.useMileage)" style="color: #00c585">
            已保养
            <div>距离下次保养{{ Number(row.nextMile)-Number(row.useMileage) }}km</div>
          </div>
          <div v-else-if="Number(row.nextMile)<Number(row.useMileage)" style="color: #ff4949">
            待保养
            <div>车辆里程已到保养标准</div>
          </div>
          <div v-else>--</div>
        </template>
      </el-table-column>
      <el-table-column label="待处理违章" prop="regulations">
        <template slot-scope="scope">
          <span v-if="scope.row.regulations>0" class="danger-text">{{scope.row.regulations}}条</span>
          <span v-else>{{scope.row.regulations}}条</span>
        </template>
      </el-table-column>
      <el-table-column label="GPS状态" prop="gpsStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.gps_status" :value="scope.row.gpsStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="{row}">
          <el-button type="text" @click="handlepeiche(row)"  v-hasPermi="['order:orderBasic:supplyCar']">确定配车</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :pageSizes="[5,10,15,20,50]" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />


  </div>
</template>

<script>
import * as api from '@/api/longOrder/index'

export default {
  dicts: ['car_status', 'mmv_jqType','gps_status'],
  props: ['orderNo'],
  data() {
    return {
      list: [],
      // 总条数
      total: 0,
      // 显示搜索条件
      showSearch: true,
      queryParams: {
        carNo: "",//车牌号
        carModelId: "",//车型id
        belongingStoreId: "",//归属门店id
        locatedStoreId: "",//停靠门店id
        carStatus: "",//车辆状态
        pageNum: 0,//页码   必选
        pageSize: 10,//每页显示数据 必选
        allModel:false//false预定车型  true全部车型
      },
    };
  },
  computed: {
    params() {
      const params = {
        carNo: this.queryParams.carNo,//车牌号
        carModelId: this.queryParams.carModelId,//车型id
        belongingStoreId: this.queryParams.belongingStoreId,//归属门店id
        locatedStoreId: this.queryParams.locatedStoreId,//停靠门店id
        carStatus: this.queryParams.carStatus,//车辆状态
        pageNum: this.queryParams.pageNum,//页码   必选
        pageSize: this.queryParams.pageSize,//每页显示数据 必选
        allModel: this.queryParams.allModel,//false预定车型  true全部车型
      };
      return params;
    },
  },
  mounted() {
    this.getList();
  },
  methods: {
    getList() {
      let param = {
        ...this.params,
        orderNo: this.orderNo
      }
      api.carListByMaintenance(param).then(response => {
        this.list = response.rows;
        this.total=response.total;
      });
    },
    // 确定配车
    handlepeiche(row) {
      const data = {
        orderNo: this.orderNo,
        carId: row.id,
      };
      // console.log(data)
      api.supplyCar(data).then(response => {
        this.$modal.msgSuccess("操作成功");
        this.$emit('close');
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
  },
}
</script>
<style>
.sucess-text{
  color: #13ce66;font-size: 12px
}
.warning-text{
  color: #ffba00;font-size: 12px
}
.danger-text{
  color: #ff4949
}
</style>
